]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shellMountDialog: Check for changes before creating new buttons
authorJonas Dreßler <verdre@v0yd.nl>
Mon, 27 Jan 2020 17:43:40 +0000 (18:43 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Mon, 27 Jan 2020 23:22:46 +0000 (23:22 +0000)
When updating the buttons of the mount dialogs, compare the new buttons
to the old ones and only create new buttons in case something changed.
This makes sure key focus isn't reset or lost unnecessarily while a
dialog is opened.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/961

js/ui/shellMountOperation.js

index 72eabe34dcaebc777ea3bd6f11da8acc8360fd80..59a4e6e0fe21c63ca1bb3cb2f1119abbc42f96ec 100644 (file)
@@ -20,18 +20,23 @@ var WORK_SPINNER_ICON_SIZE = 16;
 const REMEMBER_MOUNT_PASSWORD_KEY = 'remember-mount-password';
 
 /* ------ Common Utils ------- */
-function _setButtonsForChoices(dialog, choices) {
+function _setButtonsForChoices(dialog, oldChoices, choices) {
     let buttons = [];
+    let buttonsChanged = oldChoices.length !== choices.length;
 
     for (let idx = 0; idx < choices.length; idx++) {
         let button = idx;
+
+        buttonsChanged = buttonsChanged || oldChoices[idx] !== choices[idx];
+
         buttons.unshift({
             label: choices[idx],
             action: () => dialog.emit('response', button),
         });
     }
 
-    dialog.setButtons(buttons);
+    if (buttonsChanged)
+        dialog.setButtons(buttons);
 }
 
 function _setLabelsForMessage(content, message) {
@@ -225,13 +230,16 @@ var ShellMountQuestionDialog = GObject.registerClass({
     _init() {
         super._init({ styleClass: 'mount-question-dialog' });
 
+        this._oldChoices = [];
+
         this._content = new Dialog.MessageDialogContent();
         this.contentLayout.add_child(this._content);
     }
 
     update(message, choices) {
         _setLabelsForMessage(this._content, message);
-        _setButtonsForChoices(this, choices);
+        _setButtonsForChoices(this, this._oldChoices, choices);
+        this._oldChoices = choices;
     }
 });
 
@@ -463,6 +471,8 @@ var ShellProcessesDialog = GObject.registerClass({
     _init() {
         super._init({ styleClass: 'processes-dialog' });
 
+        this._oldChoices = [];
+
         this._content = new Dialog.MessageDialogContent();
         this.contentLayout.add_child(this._content);
 
@@ -499,7 +509,8 @@ var ShellProcessesDialog = GObject.registerClass({
     update(message, processes, choices) {
         this._setAppsForPids(processes);
         _setLabelsForMessage(this._content, message);
-        _setButtonsForChoices(this, choices);
+        _setButtonsForChoices(this, this._oldChoices, choices);
+        this._oldChoices = choices;
     }
 });